/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Aug 24, 2009 3:18:24 PM $
 *
 * Author: Eric Yang
 * Date  : Aug 24, 2009 3:18:24 PM
 *
 */
package com.gooex.domain.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.c4j.string.StringTools;

/**
 * 商品参数
 * 
 * @Author: Eric Yang
 * @version : 1.0
 */
public class Property implements Serializable {
	/** PK */
	private String id;

	/** 参数名称 */
	private String name;

	/** 是否可以基于此参数创建订单 */
	private boolean canOrdered;

	/** 参数对应的产品 */
	private Product product;

	/** 参数值列表 */
	private List<PropertyValue> values = new ArrayList<PropertyValue>();

	/* ===========functions============================= */
	/** 添加参数 */
	public void addValue(PropertyValue propertyValue) {
		if (!values.contains(propertyValue)) {
			propertyValue.setProperty(this);
			values.add(propertyValue);
		}
	}

	/** 删除参数 */
	public void removePropertyValue(PropertyValue propertyValue) {
		if (values.contains(propertyValue))
			values.remove(propertyValue);
	}

	public static List<PropertyValue> clearNullValues(List<PropertyValue> values) {
		if (values == null || values.size() == 0)
			values = new ArrayList<PropertyValue>();
		for (int i = values.size() - 1; i >= 0; i--) {
			PropertyValue value = values.get(i);
			if (StringTools.isBlankOrNull(value.getValue()))
				values.remove(i);
		}
		return values;
	}

	public void clearNullValues() {
		this.values = clearNullValues(this.values);
	}

	public void lightCopy(Property other) {
		this.canOrdered = other.canOrdered;
		this.name = other.name;
		this.product = other.product;
	}

	/* ===========setter/getter============================= */
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<PropertyValue> getValues() {
		return values;
	}

	public void setValues(List<PropertyValue> values) {
		this.values = values;
	}

	public boolean isCanOrdered() {
		return canOrdered;
	}

	public void setCanOrdered(boolean canOrdered) {
		this.canOrdered = canOrdered;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

}
